<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function People (name, age){
            this.name = name;
            this.age = age;
        }
        // var sun = new People ();
        // document.write(sun); 
        // 结果：[object Object]
        // document.write(sun.toString());
        // 结果：[object Object]
        // 打印对象，就相当于打印这个对象的toString()方法的返回值
        // 在原型对象中改写toString方法
        People.prototype.toString = function(){
            return "People[name:"+this.name+", age:"+this.age+"]";
            };
        var sun = new People("孙悟空",18);    
        var zhu = new People("猪八戒",58);    
        document.write(sun);
        // People[name:孙悟空, age:18]
        document.write(zhu);
        // People[name:猪八戒, age:58]
    </script>
</head>
<body>
    
</body>
</html>